home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / play movie / completed lab / pmutilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-06  |  4.2 KB  |  188 lines

  1. /*
  2.     File:        PMUtilities.c
  3.     
  4.     Contains:    QuickTime sample code
  5.  
  6.     Copyright:    © 2000 by Apple Computer, Inc. All rights reserved
  7.  
  8.  
  9. */
  10.  
  11. #include <MacTypes.h>
  12. #include <Gestalt.h>
  13. #include <Movies.h>
  14. #include "ComFramework.h"
  15. #include "MacFramework.h"
  16. #include "PMUtilities.h"
  17.  
  18. // Global UPP for PrePreroll
  19. // A routine descriptor for our pre-preroll completion routine
  20. MoviePrePrerollCompleteUPP gMoviePPRollCompleteProc = NULL;
  21.  
  22. //////////
  23. //
  24. // QTIsQuickTimeInstalled
  25. // Is QuickTime installed?
  26. //
  27. //////////
  28.  
  29. Boolean IsQuickTimeInstalled (void) 
  30. {
  31.     long        myAttrs;
  32.     OSErr         myErr = noErr;
  33.  
  34.     myErr = Gestalt(gestaltQuickTime, &myAttrs);
  35.  
  36.     return(myErr == noErr);
  37. }
  38.  
  39.  
  40. //////////
  41. //
  42. // QTQuickTimeCFMInstalled
  43. // Are the QuickTime CFM libraries installed?
  44. //
  45. //////////
  46.  
  47. #if TARGET_CPU_PPC
  48. Boolean IsQuickTimeCFMInstalled (void) 
  49. {
  50.     Boolean     myQTCFMAvail = false;
  51.     long        myAttrs;
  52.     OSErr         myErr = noErr;
  53.  
  54.     // Test whether the PowerPC QuickTime glue library is present
  55.     myErr = Gestalt(gestaltQuickTimeFeatures, &myAttrs);
  56.     if (myErr == noErr)
  57.         if (myAttrs & (1L << gestaltPPCQuickTimeLibPresent))
  58.             myQTCFMAvail = true;
  59.  
  60.     // Test whether a function is available (the library is not moved from the Extension folder);
  61.     // This is the trick to be used when testing if a function is available via CFM
  62.     if (!CompressImage)
  63.         myQTCFMAvail = false;     
  64.  
  65.     return(myQTCFMAvail);
  66. }
  67. #endif
  68.  
  69. void DoInitQuickTime( void )
  70. {
  71.     OSErr myErr;
  72.     
  73.     myErr = EnterMovies();
  74.     if (myErr != noErr) {
  75.         QTFrame_ShowWarning("\pCould not initialize QuickTime. Exiting.", myErr);
  76.         ExitToShell();
  77.     }
  78.     
  79.     gMoviePPRollCompleteProc = NewMoviePrePrerollCompleteProc(MoviePrePrerollCompleteProc);
  80.     
  81.     return;
  82. }
  83.  
  84. //////////
  85. //
  86. // GetWindowPositionFromFile
  87. // Return, through thePoint, the stored position of the specified movie.
  88. //
  89. // Return an error if the movie has no stored position. In any case, return a meaningful position.
  90. //
  91. //////////
  92.  
  93. OSErr GetWindowPositionFromFile (Movie theMovie, Point *thePoint)
  94. {
  95.     UserData        myUserData = NULL;
  96.     Point            myPoint = {kDefaultWindowX, kDefaultWindowY};
  97.     OSErr            myErr = paramErr;
  98.     
  99.     if (theMovie == NULL)
  100.         goto bail;
  101.         
  102.     // get the movie's user data list
  103.     myUserData = GetMovieUserData(theMovie);    // Movie specifier
  104.     
  105.     if (myUserData != NULL) {
  106.         myErr = GetUserDataItem(myUserData,                // User data list specifier
  107.                                 &myPoint,                // Recive data pointer
  108.                                 sizeof(Point),            // Size of the item
  109.                                 FOUR_CHAR_CODE('WLOC'),    // Item type specifier    
  110.                                 0);                        // Index
  111.         if (myErr == noErr) {
  112.             //  Endian Flipping Big to Native - This will do the right thing on Windows
  113.             myPoint.v = EndianS16_BtoN(myPoint.v);
  114.             myPoint.h = EndianS16_BtoN(myPoint.h);
  115.         }
  116.     }
  117.  
  118. bail:
  119.     *thePoint = myPoint;
  120.  
  121.     return(myErr);
  122. }
  123.  
  124. //////////
  125. //
  126. // MoviePrePrerollCompleteProc
  127. // A completion procedure for preprerolling movies.
  128. //
  129. // The theRefCon parameter is assumed to be a window object.
  130. //
  131. //////////
  132.  
  133. PASCAL_RTN void MoviePrePrerollCompleteProc (Movie theMovie, OSErr thePrerollErr, void *theRefCon)
  134. {
  135. #pragma unused(thePrerollErr)
  136.  
  137.     WindowObject        myWindowObject = (WindowObject)theRefCon;
  138.  
  139.     if ((theMovie == NULL) || (myWindowObject == NULL))
  140.         return;
  141.     
  142.     PrerollAndPlay(theMovie);
  143. }
  144.  
  145. //////////
  146. //
  147. // Preroll
  148. //
  149. // Preroll the movie, so that it's ready to play when we call StartMovie
  150. //
  151. //////////
  152.  
  153. void PrerollAndPlay( Movie theMovie )
  154. {
  155.     TimeValue            myTimeValue;
  156.     Fixed                myPlayRate;
  157.     
  158.     
  159.     myTimeValue = GetMovieTime(theMovie,    // Movie specifier
  160.                                NULL);        // Pointer to a time struct.
  161.     
  162.     myPlayRate = GetMoviePreferredRate(theMovie); // Movie specifier
  163.     
  164.     PrerollMovie(theMovie,        // Movie specifier
  165.                  myTimeValue,    // Starting time of segment to play as a TimeValue
  166.                  myPlayRate);    // Playback rate
  167.                  
  168.     StartPlayingMovie(theMovie, myPlayRate);
  169. }
  170.  
  171. //////////
  172. //
  173. // StartPlayingMovie
  174. // If the movie is at the end it will take it back to the beginning then start playing it.
  175. //
  176. //////////
  177.  
  178. void StartPlayingMovie(Movie theMovie, Fixed thePlayRate)
  179. {
  180.  
  181.     long theLoopingInfo;
  182.     QTUtils_GetMovieFileLoopingInfo(theMovie, &theLoopingInfo);
  183.     if(theLoopingInfo == kNoLooping)
  184.         if(GetMovieTime(theMovie, NULL) == GetMovieDuration(theMovie) && !QTUtils_IsStreamedMovie(theMovie))
  185.             GoToBeginningOfMovie(theMovie);
  186.             
  187.     SetMovieRate(theMovie, thePlayRate);
  188. }